package jk.fox.transport.netty.codec;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;
import jk.fox.serializable.kryo.KryoSerialization;
import jk.fox.serializable.Serialization;
import jk.fox.common.payload.response.RpcResponse;

import java.util.List;

/**
 * @author cuichao
 * @Description: RpcRequestDecode
 * @Date: create in 2019/12/13 9:40
 */
public class RpcResponseDecode extends ReplayingDecoder<Void> {

    private Serialization serialization = new KryoSerialization();

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {

        //获取长度
        int  len = in.readInt();
        byte[] bytes = new byte[len];
        //获取内容
        in.readBytes(bytes);
        //RpcResponse response = JSON.parseObject(bytes, RpcResponse.class);
        RpcResponse deserialize = serialization.deserialize(bytes, RpcResponse.class);
        out.add(deserialize);
    }


}
